<template>
  <el-dialog :title="dialogProps.title" :visible.sync="dialogProps.visible" width="560px"
    @open="handleDialogOpen()" v-loading="loading">
    <div slot="title" class="dialog-header">{{ dialogProps.title }}</div>
    <el-form :model="TransportLineModel" :rules="formTransportLine"
      ref="TransportLineFrom" label-width="80px" label-position="right" size="small">
      <el-form-item label="线路编号" prop="truckTypeId" label-width="120px">
        <el-col :span="16">
           <el-input :maxlength="32"  placeholder="请输入线路编号"></el-input>
        </el-col>
      </el-form-item>
       <el-form-item label="线路名称" prop="" label-width="120px">
        <el-col :span="16">
         <el-input :maxlength="32"  placeholder="请输入线路名称"></el-input>
        </el-col>
      </el-form-item>
       <el-form-item label="线路类型" prop="" label-width="120px">
        <el-col :span="16">
           <el-select placeholder="请输入线路类型">
              <!-- <el-option
                    v-for="item in parentFleet"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
            </el-option> -->
            </el-select>
          </el-col>
      </el-form-item>
     <el-form-item label="起始地机构" prop="" label-width="120px">
        <el-col :span="16">
         <el-select placeholder="请输入起始地机构">
              <!-- <el-option
                    v-for="item in parentFleet"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
            </el-option> -->
            </el-select></el-col>
      </el-form-item>
       <el-form-item label="目的地机构" prop="" label-width="120px">
        <el-col :span="16">
        <el-select placeholder="请输入目的地机构">
              <!-- <el-option
                    v-for="item in parentFleet"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id">
            </el-option> -->
            </el-select>
        </el-col>
      </el-form-item>
       <el-form-item label="距离" prop="" label-width="120px">
        <el-col :span="16"><el-input :maxlength="32"  placeholder="请输入距离"></el-input></el-col>
      </el-form-item>
      <el-form-item label="成本" prop="" label-width="120px">
        <el-col :span="16"><el-input :maxlength="32"  placeholder="请输入成本"></el-input></el-col>
      </el-form-item>
      <el-form-item label="预计时间" prop="" label-width="120px">
        <el-col :span="16"><el-input :maxlength="32"  placeholder="请输入预计时间"></el-input></el-col>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="handleDialogClose()">取 消</el-button>
      <el-button type="primary" size="small" @click="submitForm('TransportLineFrom')">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
// import axios from 'axios'
export default {
   name: "transportLine-edit",
  //  props: ['parentTruckType','parentFleet'],
    data() {
    return {
      loading: false,
      TransportLineModel: {
        
      },
      dialogProps: {
        visible: false,
        action: '',
        title: ''
      },
      formTransportLine: {
        
      }
    }
 },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          if(this.dialogProps.action === 'add') {
            this.doSaveTruck()
          }
        } else {
          return false
        }
      })
    }, 
   
    doSaveTruck() {
      // this.loading = true
      // axios.post("",this.truckModel)
      // .then(res => {
      //   console.log(res)
      //   this.loading = false
      //   this.dialogProps.visible = false
      //   this.$emit('save-finished')
      // })
      // .catch(err => {
      //   console.error(err); 
      // })
      
    },
    handleDialogClose() {
      this.dialogProps.visible = false
    },
    handleDialogOpen() {
      this.$nextTick(() => {
        this.$refs['TransportLineFrom'].clearValidate()
      })
    },
    outputError(error) {
      console.log(error.response ? error.response : error.message)
      this.loading = false
      this.$message({
        showClose: true,
        message: '出错了，请按F12查看浏览器日志。',
        type: 'error'
      })
    }
  },
   mounted: function() {
      this.$nextTick(() => {
      this.$on('openEditTransportLineDialog', function() {
        // this.GoodsTypeForm = emp
        this.dialogProps.action = 'edit'
        this.dialogProps.title = '编辑线路'
        this.dialogProps.visible = true
      })    
    this.$nextTick(() => {
      this.$on('openAddTransportLineDialog', function() {
        this.dialogProps.action = 'add'
        this.dialogProps.title = '新增线路'
        this.dialogProps.visible = true
      })
    })
      })
   }
}

</script>

<style>

</style>
